package com.dy.分类.栈队列堆.最小栈;

import java.util.Stack;

/*

 */
public class Solution {
    public static void main(String[] args) {
        System.out.println(null==null);
    }
}

class MinStack {

    Stack<Integer> data;
    Stack<Integer> min;

    /**
     * initialize your data structure here.
     */
    public MinStack() {
        data = new Stack<>();
        min = new Stack<>();

    }

    public void push(int x) {
        data.push(x);
        if (min.empty()) {
            min.push(x);
        } else {
            if (min.peek() < x) {
                min.push(min.peek());
            } else {
                min.push(x);
            }
        }
    }

    public void pop() {
        data.pop();
        min.pop();
    }

    public int top() {
        return data.peek();
    }

    public int getMin() {
        return min.peek();
    }
}

//用一个栈，每次push的时候若比栈顶小，更新min，push min，再push x，否则直接push x，pop时，如果等于min，就pop两次
class MinStack2 {

    Stack<Integer> data;
    int min = Integer.MAX_VALUE;

    /**
     * initialize your data structure here.
     */
    public MinStack2() {
        data = new Stack<>();
    }

    public void push(int x) {

        if (x <= min) {
            data.push(min);
            min = x;

        }

        data.push(x);

    }


    public void pop() {
        if(min==data.pop())min=data.pop();
    }

    public int top() {
        return data.peek();
    }

    public int getMin() {
        return min;
    }
}
